<template>
  <div class="homecontent" id="homecontent">
    <component v-for="(item,key) in AllContent" :key="item.id" :is="item.name" v-if="!!item.data && !!item.data[0]" :cdata="item.data"></component>
  </div>
</template>
<script>


// import { getHomeContent } from '@/service/getData'

import Slider from './components/slider'
import UnderBanner from './components/underbanner'
import Navlist from './components/nav'
import Notice from './components/notice'
import TimeTitle from './components/time_title'
import GoodsScroll from './components/goods_scroll'
import ImgTwo from './components/img_two'
import mTitle from './components/Title'
import ImgBigger from './components/img_bigger'
import Goods1h2g from './components/goods_1h2g'
import GoodsInter from './components/goods_inter'
import specialScroll from './components/special_scroll'
import NewFloor1 from './components/newFloor1'
import NewFloor2 from './components/newFloor2'
import NewFloor3 from './components/newFloor3'
import NewFloat from './components/new_float'
import Xhtitle from './components/xhtitle'
import AdFloat from './components/ad_float'
import Img2b1b from './components/img_2b1b'
import Img2s1b from './components/img_2s1b'
import Img2sShort from './components/img_2sshort'
import Img1b2b from './components/img_1b2b'
import Img1b2s from './components/img_1b2s'
import ZnhjOne from './components/znhj_oneGoods' // 只能货架每楼层一个商品
import ZnhjTwo from './components/znhj_twoGoods' // 只能货架每楼层一个商品
import { mapState, mapGetters, mapMutations } from 'vuex'
import {
  snxd,
  img,
  cmslib
} from '../../config/env'
import fetch from '@/config/fetch'
import * as model from '@/config/homeModel.json'


export default {
  data() {
    return {
      AllContent: []
    }
  },
  created() {
    let tag = this.$route.params.type
    this.$store.commit('SET_INDEX_TAG', tag)
    //this.$store.commit('updateLoading', true)
    this.$store.commit('showMask', true)
    this.getHomeContent()
  },
  components: {
    Img1b2s,
    Img2sShort,
    Img1b2b,
    Img2s1b,
    Img2b1b,
    AdFloat,
    Xhtitle,
    NewFloat,
    NewFloor3,
    NewFloor2,
    NewFloor1,
    UnderBanner,
    Slider,
    Navlist,
    Notice,
    TimeTitle,
    GoodsScroll,
    mTitle,
    ImgTwo,
    ImgBigger,
    Goods1h2g,
    GoodsInter,
    specialScroll,
    ZnhjOne,
    ZnhjTwo
  },

  methods: {
    getHomeContent() {
      this.AllContent= []
      fetch({
        url: cmslib + '/api/aysn/page/' + this.indextag + '.jsonp',
        params: {},
        jsonp: 'callback',
        jsonpCallback: 'cmsPageCallback'
      }).then(res => {
        let getMsg = []
        let content = res
        for (var i in content) {
          let name = model[content[i].modelCode]
          let data = content[i].modelList
          let a = {
            'name': name,
            'data': data,
            'show': true
          }
          getMsg.push(a)
        }
        this.AllContent = getMsg;
        //this.$store.commit('updateLoading', false)
        this.$store.commit('showMask', false)
      })
    },
    changeLog() {
      //this.$store.commit('updateLoading', true)
      let tag = this.$route.params.type
      this.$store.commit('SET_INDEX_TAG', tag)
      this.getHomeContent();
      // this.$store.dispatch('getHomeContent')
    }
  },
  computed: {
    ...mapGetters([
      'indextag'
    ])
  },
  watch: {
    '$route': 'changeLog',
  }
}
</script>

<style lang="scss" scoped>
@import './components/tool.scss';
</style>
